home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / ISRAMDSK.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  1KB  |  57 lines

  1. /*
  2. **  isRamDsk() - Determine if a drive is a RAM disk
  3. **
  4. **  Call with drive letter ('a' - 'z', 'A' - 'Z')
  5. **
  6. **  Returns TRUE, FALSE, or ERROR
  7. **
  8. **  Uses ABSDISKC.C, ABSDISK.ASM, and DOS5BOOT.H from SNIPPETS
  9. **  (Note: The relevent parts of the structure in DOS5BOOT.H are
  10. **   also applicable to lower version numbers of DOS)
  11. **
  12. **  Public domain by Bob Stout
  13. */
  14.  
  15. #include <stdlib.h>
  16. #include <ctype.h>
  17. #include <dos.h>
  18. #include "dos5boot.h"
  19.  
  20. int AbsDiskRead(unsigned short, size_t, size_t, void *);
  21.  
  22. typedef enum {ERROR = -1, FALSE, TRUE} LOGICAL;
  23.  
  24. LOGICAL isRamDsk(unsigned char drive) 
  25. {
  26.       union REGS regs;
  27.       B_REC buffer;
  28.  
  29.       regs.x.ax = 0x4408;           /* Not if removable     */
  30.       regs.h.bl = (unsigned)toupper(drive) - (unsigned char)'@';
  31.       intdos(®s, ®s);
  32.       if (0 == regs.x.ax)
  33.             return FALSE;
  34.       if (AbsDiskRead(toupper(drive) - 'A', 1, 0, &buffer))
  35.             return ERROR;
  36.       return (1 == buffer.bsFATs);
  37.  
  38. #ifdef TEST
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42.  
  43. int main(int argc, char *argv[])
  44. {
  45.       if (2 > argc)
  46.       {
  47.             puts("Syntax: ISRAMDSK drive_letter");
  48.             return EXIT_FAILURE;
  49.       }
  50.       printf("Drive %c: is%s a RAM drive\n", toupper(*argv[1]),
  51.             isRamDsk(*argv[1]) ? "" : " not");
  52.       return EXIT_SUCCESS;
  53. }
  54.  
  55. #endif /* TEST */
  56.